<template>
  <div class="t-loading" v-if="showLoading">
    <div class="t-loading-box">
      <div class="loading-center">
        <div class="loading-center-absolute">
          <div class="object"></div>
          <div class="object"></div>
          <div class="object"></div>
          <div class="object"></div>
          <div class="object"></div>
          <div class="object"></div>
          <div class="object"></div>
          <div class="object"></div>
          <div class="object"></div>
          <div class="object"></div>
        </div>
      </div>
      <div class="t-loading-text">
        {{ text }}
        <slot />
      </div>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    value: {
      type: Boolean,
      default: false,
    },
    text: {
      type: String,
      default: "加载中...",
    },
  },
  watch: {
    value(v) {
      this.showLoading = v;
      this.$emit("input", v);
    },
  },
  mounted() {
    this.showLoading = this.value;
  },
  data() {
    return {
      showLoading: false,
    };
  },
};
</script>
<style lang="scss" scoped>
.t-loading {
  background-color: rgba($color: #000000, $alpha: 0.5);
  position: fixed;
  z-index: 9999999;
  margin-top: 0px;
  left: 0;
  top: 0;
  bottom: 0;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}
.t-loading-box {
  background-color: #fff;
  border-radius: 10px;
  padding: 50px;
  box-shadow: 0px 0px 9px 4px #6d6d6d;
}
.t-loading-center {
  width: 100%;
  height: 100%;
  position: relative;
}
.t-loading-center-absolute {
  position: absolute;
  left: 50%;
  top: 50%;
  height: 50px;
  width: 150px;
  margin-top: -25px;
  margin-left: -75px;
}
.object {
  width: 8px;
  height: 50px;
  margin-right: 5px;
  background-color: $type-primary;
  -webkit-animation: animate 1s infinite;
  animation: animate 1s infinite;
  float: left;
}
.t-loading-text {
  text-align: center;
  font-weight: bold;
  font-size: 16px;
  color: $type-primary;
  margin-top: 80px;
  user-select: none;
  animation: flash 4000ms infinite both;
}
@keyframes flash {
  from,
  50%,
  to {
    opacity: 1;
  }

  25%,
  75% {
    opacity: 0;
  }
}
.object:last-child {
  margin-right: 0px;
}

.object:nth-child(10) {
  -webkit-animation-delay: 0.9s;
  animation-delay: 0.9s;
}
.object:nth-child(9) {
  -webkit-animation-delay: 0.8s;
  animation-delay: 0.8s;
}
.object:nth-child(8) {
  -webkit-animation-delay: 0.7s;
  animation-delay: 0.7s;
}
.object:nth-child(7) {
  -webkit-animation-delay: 0.6s;
  animation-delay: 0.6s;
}
.object:nth-child(6) {
  -webkit-animation-delay: 0.5s;
  animation-delay: 0.5s;
}
.object:nth-child(5) {
  -webkit-animation-delay: 0.4s;
  animation-delay: 0.4s;
}
.object:nth-child(4) {
  -webkit-animation-delay: 0.3s;
  animation-delay: 0.3s;
}
.object:nth-child(3) {
  -webkit-animation-delay: 0.2s;
  animation-delay: 0.2s;
}
.object:nth-child(2) {
  -webkit-animation-delay: 0.1s;
  animation-delay: 0.1s;
}

@-webkit-keyframes animate {
  50% {
    -ms-transform: scaleY(0);
    -webkit-transform: scaleY(0);
    transform: scaleY(0);
  }
}

@keyframes animate {
  50% {
    -ms-transform: scaleY(0);
    -webkit-transform: scaleY(0);
    transform: scaleY(0);
  }
}
</style>